#include "calctest.h"
#include "ui_calctest.h"

CalcTest::CalcTest(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::CalcTest)
{
    ui->setupUi(this);
}

CalcTest::~CalcTest()
{
    delete ui;
}

void CalcTest::on_add_clicked()
{
    QString first = ui->firstNum->text();
    QString second = ui->secondNum->text();
    ui->label->setText("+");

    //把字符串转数值再进行计算
    double result = first.toDouble()+second.toDouble();

    //结果显示--把数值result转字符串
    ui->result->setText(QString::number(result));
}

void CalcTest::on_sub_clicked()
{
    QString first = ui->firstNum->text();
    QString second = ui->secondNum->text();
    ui->label->setText("-");

    //把字符串转数值再进行计算
    double result = first.toDouble()-second.toDouble();

    //结果显示--把数值result转字符串
    ui->result->setText(QString::number(result));
}

void CalcTest::on_mul_clicked()
{
    QString first = ui->firstNum->text();
    QString second = ui->secondNum->text();
    ui->label->setText("*");

    //把字符串转数值再进行计算
    double result = first.toDouble()*second.toDouble();

    //结果显示--把数值result转字符串
    ui->result->setText(QString::number(result));
}

void CalcTest::on_devl_clicked()
{
    QString first = ui->firstNum->text();
    QString second = ui->secondNum->text();
    ui->label->setText("/");

    //把字符串转数值再进行计算
    double result = first.toDouble()/second.toDouble();

    //结果显示--把数值result转字符串
    ui->result->setText(QString::number(result));
}
